﻿using AutoMapper;
using Jinjia.Approve.Entity.Entity;
using Jinjia.Approve.Model.Input;
using Jinjia.Approve.Model.VM;

namespace Jinjia.Approve.Model.AutoMapperProfile
{
    public class HelloWorldProfile : Profile
    {
        public HelloWorldProfile()
        {
            #region 指定来源于目标映射字段规则

            // SourceMemberNamingConvention = new PascalCaseNamingConvention();
            // DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
            // 如上述示例:
            // CreateMap<Destination, Source>()
            //  则对应规则为 => Destination中的属性命名规则为下划线命名法,
            //                Source中的属性命名为大驼峰命名法
            // 若字段名差距非大小写差距, 则需要手动指定映射
            
            #endregion
            
            CreateHelloWorldCreateMaps();
            CreateHelloWorldVMMaps();
        }

        private void CreateHelloWorldCreateMaps()
        {
            CreateMap<hello_world_tbl, HelloWorldCreateInput>()
                .ForMember(des => des.Key,
                    opt => 
                        opt.MapFrom(x => x.key))
                .ForMember(des => des.Value,
                    opt => 
                        opt.MapFrom(x => x.value))
                .ReverseMap();
        }

        private void CreateHelloWorldVMMaps()
        {
            CreateMap<hello_world_tbl, HelloWorldVM>().ReverseMap();
        }
    }
}